<?php
/*
Primary Author: Derek Shue
Updated: 12/10/2011

Module Description: ContactsQuery provides interfaces to the CPcontacts table to access
contacts using $cpid.
*/

class Application_Model_ContactsQuery
{
    public function init(){
	}
		
		
	/**
		Returns the primary contact for the partner $cpid
	*/
	public function getPrimaryContact_CP($cpid){

		$contacts = new Application_Model_DbTable_CpContacts();
		$query = 'CPID = ' . $cpid . " AND PRIMARYCONTACT = 'yes'";
	
		try{
			$rows = $contacts->getCPContact($query);
		}
		
		catch(Exception $e){
			$rows = Null;
		}
		return $rows;
	}	
	
	/**
	Returns the primary contact for the volunteer request $vrid
	*/
	public function getPrimaryContact_VR($vrid){
		$volModel = new Application_Model_DbTable_VolunteerRequests();
		$contacts = new Application_Model_DbTable_CpContacts();
		try{
			$vrow = $volModel->getVolunteerRequest('VRID = '.$vrid);
			$cpid = $vrow['CPID'];
			$query = 'CPID = ' . $cpid . " AND PRIMARYCONTACT = 'yes'";
			$rows = $contacts->getCPContact($query);
		}
	
		catch(Exception $e){
			$rows = Null;
		}
		return $rows;
	}
	
	/**
		Returns all contacts for the partner $cpid
	*/	
    public function getContacts_CP($cpid){
		$contacts = new Application_Model_DbTable_CpContacts();
		$query = 'CPID = ' . $cpid;
	
	try{
	    $rows = $contacts->fetchAll($query);
	}
	
	catch(Exception $e){
	    $rows = Null;
	}
	return $rows;
    }
}

?>
